<template>
  <view class="job-card" @click="handleCardClick">
    <view class="job-header">
      <text class="job-title">{{ jobData.title }}</text>
      <text class="job-salary">查看更多》</text>
    </view>

    <view class="job-tags" v-if="jobData.tags && jobData.tags.length > 0">
      <text class="tag" v-for="(tag, tagIndex) in jobData.tags" :key="tagIndex">
        {{ tag }}
      </text>
    </view>

    <view class="job-company">
      <view class="company-avatar">
        <image :src="jobData.company.avatar" :alt="jobData.company.name + ' logo'" />
      </view>
      <view class="company-info">
        <text class="company-name">{{ jobData.company.name }} 8.4km</text>
        <text class="company-location">{{ jobData.company.location }}</text>
      </view>
      <!-- <view class="apply-btn" @click.stop="handleApplyClick">
        <text>{{ applyButtonText }}</text>
      </view> -->
    </view>

    <view class="job-content">
      <view class="job-info" v-for="i in 3">
        <view class="job-time">10月17日 周五 11:00-20:00</view>
        <view class="job-price">
          <text class="job-price-text">￥105</text>
          <text class="iconfont-v2 icon-xueyuan filter-icon"></text>
          <text class="job-ren-text"><text class="nums">2</text>/5</text>
        </view>
      </view>
    </view>
    
  </view>
</template>

<script>
/**
 * 招聘信息卡片组件
 * @description 通用的招聘信息展示卡片，支持自定义按钮文本和事件处理
 * @author 系统
 * @date 2024
 */

export default {
  name: 'JobCard',
  props: {
    /**
     * 工作信息数据
     * @type {Object}
     * @required
     */
    jobData: {
      type: Object,
      required: true,
      validator: (value) => {
        return value && 
               typeof value.title === 'string' &&
               typeof value.salary === 'string' &&
               value.company &&
               typeof value.company.name === 'string'
      }
    },
    /**
     * 申请按钮文本
     * @type {String}
     * @default '立即申请'
     */
    applyButtonText: {
      type: String,
      default: '立即申请'
    },
    /**
     * 是否显示申请按钮
     * @type {Boolean}
     * @default true
     */
    showApplyButton: {
      type: Boolean,
      default: true
    },
    /**
     * 卡片样式变体
     * @type {String}
     * @default 'default'
     * @options 'default' | 'compact' | 'detailed'
     */
    variant: {
      type: String,
      default: 'default',
      validator: (value) => ['default', 'compact', 'detailed'].includes(value)
    }
  },
  computed: {
    // 计算卡片样式类
    cardClass() {
      return [
        'job-card',
        `job-card--${this.variant}`
      ]
    },
    // 计算按钮样式类
    buttonClass() {
      return [
        'apply-btn',
        {
          'apply-btn--hidden': !this.showApplyButton
        }
      ]
    }
  },
  methods: {
    /**
     * 处理卡片点击事件
     */
    handleCardClick() {
      this.$emit('card-click', this.jobData)
      
      // 跳转到职位详情页
      uni.navigateTo({
        url: `/pages/fast/job-detail?id=${this.jobData.id}`
      })
    },
    
    /**
     * 处理申请按钮点击事件
     */
    handleApplyClick() {
      this.$emit('apply-click', this.jobData)
      
      // 显示申请确认弹窗
      uni.showModal({
        title: '确认申请',
        content: `确定要申请《${this.jobData.title}》吗？`,
        success: (res) => {
          if (res.confirm) {
            this.$emit('apply-confirm', this.jobData)
            uni.showToast({
              title: '申请已提交',
              icon: 'success'
            })
          }
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.job-card {
  background: white;
  border-radius: 24rpx;
  padding: 30rpx;
  margin-bottom: 20rpx;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition: all 0.3s ease;

  &:hover {
    transform: translateY(-4rpx);
    box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.12);
  }

  .job-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20rpx;

    .job-title {
      font-size: 32rpx;
      font-weight: 600;
      color: #333;
      flex: 1;
      line-height: 1.4;
      margin-right: 20rpx;
    }

    .job-salary {
      font-size: 28rpx;
      font-weight: 600;
      color: #ED6567;
      white-space: nowrap;
    }
  }

  .job-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 12rpx;
    margin-bottom: 20rpx;

    .tag {
      background: #f0f0f0;
      color: #666;
      padding: 6rpx 16rpx;
      border-radius: 20rpx;
      font-size: 22rpx;
      font-weight: 500;
    }
  }

  .job-company {
    display: flex;
    align-items: center;
    gap: 20rpx;

    .company-avatar {
      width: 80rpx;
      height: 80rpx;
      border-radius: 50%;
      overflow: hidden;

      image {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }

    .company-info {
      flex: 1;

      .company-name {
        font-size: 28rpx;
        font-weight: 500;
        color: #333;
        margin-bottom: 8rpx;
        display: block;
      }

      .company-location {
        font-size: 24rpx;
        color: #666;
        display: block;
      }
    }

    .apply-btn {
      background: #ED6567;
      color: white;
      border-radius: 40rpx;
      padding: 16rpx 32rpx;
      font-size: 26rpx;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.3s ease;
      white-space: nowrap;

      &:hover {
        background: #d55a54;
      }

      &--hidden {
        display: none;
      }

      text {
        color: white;
      }
    }
  }

  .job-content{
    padding-left: 100rpx;
  }
  .job-info {
    margin-top: 20rpx;
    padding-top: 20rpx;
    border-top: 1rpx solid #f0f0f0;

    .job-time {
      font-size: 26rpx;
      color: #666;
      font-weight: 500;
      margin-bottom: 12rpx;
    }

    .job-price {
      display: flex;
      align-items: center;
      gap: 12rpx;

      .job-price-text {
        font-size: 32rpx;
        font-weight: 600;
        color: #ED6567;
      }

      .filter-icon {
        font-size: 32rpx;
        color: #999;
        margin-left: auto;
      }

      .job-ren-text {
        font-size: 24rpx;
        color: #666;
        font-weight: 500;
        .nums{
          color: #ED6567;
        }
      }
    }
  }
}
</style>